package top.zhangjianyong.tools.factory;

import top.zhangjianyong.tools.entity.Guaguale;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/13 9:27 AM
 */
public class GuagualeFactory {

    public static Guaguale create() {
        return new Guaguale();
    }

    public static Guaguale create(String type, String code, int ticketPrice, int bonus) {
        Guaguale guaguale = create();
        guaguale.setType(type);
        guaguale.setCode(code);
        String[] split = code.split("-");
        if (split.length > 0) guaguale.setCode1(split[0]);
        if (split.length > 1) guaguale.setCode2(split[1]);
        if (split.length > 2) guaguale.setCode3(split[2]);
        if (split.length > 3) guaguale.setCode4(split[3]);
        if (split.length > 4) guaguale.setCode5(split[4]);
        BigDecimal bonusDecimal = new BigDecimal(bonus);
        BigDecimal ticketPriceDecimal = new BigDecimal(ticketPrice);
        guaguale.setBonus(bonusDecimal);
        guaguale.setTicketPrice(ticketPriceDecimal);
        guaguale.setRate(bonusDecimal.divide(ticketPriceDecimal, 2, RoundingMode.HALF_UP));
        return guaguale;
    }
}
